<%@page import="com.bill.common.utils.TranType"%>
<%@page import="com.bill.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.bill.common.system.service.ITransactionRecordService"%>
<%@page import="com.bill.common.user.dto.AccountDTO"%>
<%@page import="com.bill.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/transfer.jsp");
	return;
}
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
TransactionRecordDTO trDTO = new TransactionRecordDTO();
trDTO.setLoginName((String)session.getAttribute("loginName"));
trDTO.setTransactionTypes(new String[]{TranType.ZhuanZhang});

int pages = 1;
if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;
trDTO.setStart( start );
trDTO.setLimit( rows );

PageDTO transferPageDTO = transactionRecordService.findTransactionRecordPager(trDTO,"desc","optDate");
if(transferPageDTO!=null){
	transferPageDTO.setPage( pages );
	transferPageDTO.setRows( rows );
}
request.setAttribute("pageDTO",transferPageDTO);
//可提现余额
Double trbalance1 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Dynamic");
request.setAttribute("trbalance1",trbalance1);
/* Double staticBalance = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Static");
request.setAttribute("staticBalance",staticBalance); */

IAccountService acService = (IAccountService)ac.getBean("accountService");
AccountDTO transferDto = acService.findAccountInfo();
request.setAttribute("transferDto",transferDto);

request.setAttribute("pageUrl","transfer.jsp?");

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title><fmt:message key="i18n.salesTotal"/>-<fmt:message key="i18n.title"/> </title>
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	
	<link rel="shortcut icon" href="../index/favicon.png" />
	
	<!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
    
	 <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/tables.css" type="text/css" media="screen" />
    
	<link rel="stylesheet" href="../styles/myStyle.css" />
</head>
<body>

	<!-- main container -->
	<div class="content container-fluid">
		<!-- BreadcrumbNavigation -->
        <div class="row-fluid head">
            <div class="span12">
                <h4><fmt:message key="i18n.moneyManage"/>&gt; <fmt:message key="i18n.accountZhuanZhang"/></h4>
            </div>
        </div>
        <!-- End BreadcrumbNavigation -->
        <!-- list table -->
        <div class="table-wrapper orders-table section">
        	<div class="row-fluid head">
                <div class="span12">
                    <p class="tableTopTip">
                    	<fmt:message key="i18n.dyAccount"/>：${trbalance1}
					</p>
                </div>
            </div>
			<form id="transfer_form" action="registerUser!userOpt.action" method="post">
				<input type="hidden" name="optType" value="ZhuanZhang" />
				<input type="hidden" name="pageUrl" value="transfer.jsp" />
		 		<div class="row-fluid filter-block">
	                <div class="pull-left">
	                	<div>
		                	<fmt:message key="i18n.accountBag"/>:
	                        <select name="dtype" class="tx_contBoxR2_1">
									<option value="Dynamic"><fmt:message key="i18n.dyAccount"/></option>
									<%-- <option value="Static"><fmt:message key="i18n.jtAccount"/></option> --%>
							</select>
						</div>
                        <div>
                        	<fmt:message key="i18n.zhuanruAcount"/>:
							<input type="text" id="transfer_transAccount" name="transAccount" class="easyui-validatebox tx_contBoxR3"  onBlur="findUserNameByLoginName()" />
							<span style="color: red;">&nbsp;&nbsp;*</span>
							<fmt:message key="i18n.piUserName"/>:<span id="transfer_userName"></span>
							<input name="loginName222" value="${session.loginName }" type="hidden">
						</div>
						
						<div>
							<fmt:message key="i18n.zhuanZhangMoney"/>:
							<input type="tel" id="transfer_value" name="value" class="easyui-validatebox easyui-numberbox tx_contBoxR3" />
							<span style="color: red;">&nbsp;&nbsp;*</span>
						</div>
						<div>
							<c:if test="${not empty session.activationTime}">
		                   		<a class="btn-flat success new-product" href="javascript:checkform('${user.loginName}')" ><fmt:message key="i18n.confimzhuanZhang"/></a>
		                    </c:if>
	                    </div>
	                </div>
	            </div>
			</form>
			
			<div class="row-fluid">
				<table class="table table-hover">
					<thead>
						<tr>
				        	<th scope="col"><fmt:message key="i18n.type"/></th>
							<th scope="col"><fmt:message key="i18n.zhuanZhangUser"/></th>
							<th scope="col"><fmt:message key="i18n.zhichu"/></th>
							<th scope="col"><fmt:message key="i18n.income"/></th>
							<th scope="col"><fmt:message key="i18n.detail"/></th>
							<th scope="col"><fmt:message key="i18n.zhuanZhangTime"/></th>
						</tr>
					</thead>
                    <tbody>
						<c:forEach items="${pageDTO.data}" var="data">
						<tr>
		   					<td><fmt:message key="${data.transactionType }" /></td>
							<td>${data.transactionObject }</td>
							<td>${data.expenditure }</td>
							<td>${data.income }</td>
							<td>${data.remark}</td>
							<td><fmt:formatDate value="${data.optDate}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
		   				</tr>
			   			</c:forEach>
						<c:if test="${empty pageDTO.data}">
						<tr>
							<td colspan="6" style="text-align: center;"><fmt:message key="i18n.noData"/></td>
						</tr>
						</c:if> 
                    </tbody>
				</table>
			</div>
			<div class="pagination">
				<ul>
		            <li><a href="${pageUrl }&pages=${pageDTO.page-1}">&#8249;</a></li>
		            <li><a <c:if test="${pageDTO.page eq 1}"> class="active" </c:if> href="${pageUrl }&pages=1">1</a></li>
		            <c:if test="${pageDTO.total ge 2}">
		            <li><a <c:if test="${pageDTO.page eq 2}"> class="active" </c:if> href="${pageUrl }&pages=2">2</a></li>
		            </c:if>
		            <c:if test="${pageDTO.total ge 3}">
		            <li><a <c:if test="${pageDTO.page eq 3}"> class="active" </c:if> href="${pageUrl }&pages=3">3</a></li>
		            </c:if>
		            <c:if test="${pageDTO.total ge 4}">
		            <li><a <c:if test="${pageDTO.page eq 4}"> class="active" </c:if> href="${pageUrl }&pages=4">4</a></li>
		            </c:if>
		            <li><span style="font-size: 10px;"> ${pageDTO.page}/${pageDTO.total} | <fmt:message key="i18n.total"/>${pageDTO.totalSize} </span></li>
		            <li><a href="${pageUrl }&pages=${pageDTO.page+1}">&#8250;</a></li>
		            
		            
	          	</ul>
	          	
	        </div>
		</div>
        <!-- end list table -->
        
    </div>


  
	<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
	<script>
	
	function findUserNameByLoginName(loginName){
		$.post('registerUser!findUserNameByLoginName.action','registerUserDTO.loginName='+$('#transfer_transAccount').val(),function(res){
			$('#transfer_userName').text(res);
		});	
	}
	
	function checkform(){
		if($('#transfer_transAccount').val()==''){
			alert('Into account cannot be empty(转入账号不能为空)!');
			$('#transfer_transAccount').focus();
			return false;
		}
		if($('#transfer_value').val()==''){
			alert('Transferred to the amount can not be empty(转入金额不能为空)!');
			$('#transfer_value').focus();
			return false;
		}
		var toMoeny = $('#transfer_value').val()
		if(toMoeny!=''){
			toMoeny = toMoeny.replace(/(^\s*)|(\s*$)/g, ""); 
		}
		var a = /^(\d*|\-?[1-9]{1}\d*)$/;
		if(!toMoeny.match(a) || toMoeny==0){
			alert("Transferred to the amount of not positive integer(转入金额不是正整数)!");
			return false;
		}
		if(toMoeny % 100 != 0){
			alert('Please enter 10 times the amount(请输入100的倍数金额)!');
			return false;
		}
		$('#transfer_form').submit();
		/**
		$.post('activationCode!authEmailCode.action','dto.type=邮件&dto.category=转账&dto.activationCode='+$('#transfer_validCode').val(),function(res){
			 if(!res){
				 alert('邮箱验证码不正确!');
				 return false;
			 }else{
				 $('#transfer_form').submit();
			 }
		});
		**/
	}
	
	
	</script>
</body>
</html>